{
 "cells": [
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": "# Escape speed",
   "id": "49012efb211da070"
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-12-03T17:02:02.885681Z",
     "start_time": "2024-12-03T17:02:02.732096Z"
    }
   },
   "cell_type": "code",
   "source": [
    "import numpy as np\n",
    "import astropy.constants as c\n",
    "import astropy.units as u"
   ],
   "id": "914c71ab45d16ff7",
   "outputs": [],
   "execution_count": 1
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-12-03T17:02:02.890180Z",
     "start_time": "2024-12-03T17:02:02.888479Z"
    }
   },
   "cell_type": "code",
   "source": [
    "def escape_speed(M, R):\n",
    "    return np.sqrt(2*c.G*M/R).to(u.km/u.s)"
   ],
   "id": "8e0a9e8de261e1a1",
   "outputs": [],
   "execution_count": 2
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-12-03T17:02:02.926665Z",
     "start_time": "2024-12-03T17:02:02.922787Z"
    }
   },
   "cell_type": "code",
   "source": "escape_speed(c.M_earth, c.R_earth)",
   "id": "3c65979846cb1ecb",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<Quantity 11.17990726 km / s>"
      ],
      "text/latex": "$11.179907 \\; \\mathrm{\\frac{km}{s}}$"
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 3
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-12-03T17:02:02.933468Z",
     "start_time": "2024-12-03T17:02:02.930884Z"
    }
   },
   "cell_type": "code",
   "source": "escape_speed(c.M_sun, c.R_sun)",
   "id": "64cc46e89cf4311c",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<Quantity 617.67470028 km / s>"
      ],
      "text/latex": "$617.6747 \\; \\mathrm{\\frac{km}{s}}$"
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 4
  },
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": "# Schwarzschild radius",
   "id": "f95579201316dd38"
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-12-03T17:02:02.944386Z",
     "start_time": "2024-12-03T17:02:02.942549Z"
    }
   },
   "cell_type": "code",
   "source": [
    "def R_schwarzschild(M):\n",
    "    return 2*c.G*M/c.c**2"
   ],
   "id": "6058d925c11b60cb",
   "outputs": [],
   "execution_count": 5
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-12-03T17:02:02.954292Z",
     "start_time": "2024-12-03T17:02:02.951442Z"
    }
   },
   "cell_type": "code",
   "source": "R_schwarzschild(c.M_earth)",
   "id": "e107877031018c2c",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<Quantity 0.00887006 m>"
      ],
      "text/latex": "$0.0088700551 \\; \\mathrm{m}$"
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 6
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-12-03T17:14:03.462416Z",
     "start_time": "2024-12-03T17:14:03.457652Z"
    }
   },
   "cell_type": "code",
   "source": "R_schwarzschild(c.M_jup)",
   "id": "567f0d26aeb0385c",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<Quantity 2.81915549 m>"
      ],
      "text/latex": "$2.8191555 \\; \\mathrm{m}$"
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 8
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-12-03T17:02:02.965620Z",
     "start_time": "2024-12-03T17:02:02.962900Z"
    }
   },
   "cell_type": "code",
   "source": "R_schwarzschild(c.M_sun)",
   "id": "8f13ec1d1285c2a9",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<Quantity 2953.2500761 m>"
      ],
      "text/latex": "$2953.2501 \\; \\mathrm{m}$"
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 7
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-12-03T17:35:16.519277Z",
     "start_time": "2024-12-03T17:35:16.515991Z"
    }
   },
   "cell_type": "code",
   "source": "R_schwarzschild(c.M_sun*10)",
   "id": "b8682566a5861a9a",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<Quantity 29532.500761 m>"
      ],
      "text/latex": "$29532.501 \\; \\mathrm{m}$"
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 9
  },
  {
   "metadata": {},
   "cell_type": "code",
   "outputs": [],
   "execution_count": null,
   "source": "",
   "id": "b97973cdf2d98cf4"
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
